<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>ToDoList</title>
    <style>
        *{
            list-style: none;
            margin: 0;
            padding: 0;
        }

        #app{
            width: 300px;
            margin: 100px auto;
        }

        #app h2{
            margin: 20px;
        }
    </style>
</head>
<body>
    <div id="app">
        ToDoList:<input v-model="val" type="text" placeholder="添加ToDo">
        <button @click="add">添加</button>
        <h2>正在进行---------- {{len}}</h2>
        <ul>
            <li v-for="(item,index) in arr" v-show="!item.checked">
                <input v-model="item.checked" type="checkbox">
                {{item.val}}
                <button @click="del">删除</button>
            </li>
        </ul>
        <h2>已经完成 ---------- {{arr.length - len}}</h2>
        <ul>
            <li v-for="(item,index) in arr" v-show="item.checked">
                <input v-model="item.checked" type="checkbox">
                {{item.val}}
                <button @click="del">删除</button>
            </li>
        </ul>
    </div>

    <!-- 引入 Vue -->
    <script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>

    <script>
        new Vue({
            el:'#app',
            data:{
                val:"",
                arr:[]
            },
            computed:{
                len(){
                    return this.arr.filter((item)=>{
                        return item.checked === false
                    }).length
                }
            },
            methods:{
                add(){
                    this.arr.push({
                        val:this.val,
                        checked:false
                    })
                    this.val = ''
                },
                del(){
                    this.arr.pop({
                        val:this.val,
                        checked:false
                    })
                }
            }
        })
    </script>
</body>
</html>